import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

Rectangle {
    Layout.fillWidth: true
    Layout.fillHeight: true

    Column {
        spacing: 15
        anchors.centerIn: parent
        width: parent.width * 0.8
        height: parent.height * 0.8

        TextArea {
            id: wrapTextArea
            width: parent.width
            height: parent.height - 40
            text: "TextArea is not scrollable by itself. Especially on screen-size constrained platforms, it is often preferable to make entire application pages scrollable. On such a scrollable page, a non-scrollable TextArea might behave better than nested scrollable controls."
            placeholderText: "选择换行模式..."
            clip: true
            selectByMouse: true
        }

        Row {
            spacing: 10
            anchors.horizontalCenter: parent.horizontalCenter

            Button {
                text: "不换行"
                onClicked: {
                    wrapTextArea.wrapMode = TextArea.NoWrap
                    //让wrapMode立即生效
                    wrapTextArea.width = wrapTextArea.width - 1
                    wrapTextArea.width = wrapTextArea.width + 1
                }
            }

            Button {
                text: "单词换行"
                onClicked: {
                    wrapTextArea.wrapMode = TextArea.Wrap
                    //让wrapMode立即生效
                    wrapTextArea.width = wrapTextArea.width - 1
                    wrapTextArea.width = wrapTextArea.width + 1
                }
            }

            Button {
                text: "任意位置换行"
                onClicked: {
                    wrapTextArea.wrapMode = TextArea.WrapAnywhere
                    //让wrapMode立即生效
                    wrapTextArea.width = wrapTextArea.width - 1
                    wrapTextArea.width = wrapTextArea.width + 1
                }
            }
        }
    }
}
